package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC349 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] intersection(int[] arr1, int[] arr2) {
            Set<Integer> matchSet = new HashSet<>();
            Set<Integer> misSet = new HashSet<>();
            for (int num : arr1) {
                if (matchSet.contains(num)) continue;
                if (misSet.contains(num)) continue;
                for (int num2 : arr2) {
                    if (num == num2) {
                        matchSet.add(num);
                        break;
                    }
                }
                misSet.add(num);
            }

            int[] res = new int[matchSet.size()];
            int i = 0;
            for (Integer num : matchSet) {
                res[i++] = num;
            }
            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC349 an = new LC349();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
